unit Con_MotCanc;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls, Buttons, ExtCtrls,
  Db,Dbtables;

type
  TFrmCon_MotCanc = class(TFrmConsulta)
    Label1: TLabel;
    EdtDescricao: TEdit;
    DbgMotCanc: TDBGrid;
    procedure BtnFecharClick(Sender: TObject);
    procedure EdtDescricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Canp_codigo : String;
  end;

var
  FrmCon_MotCanc: TFrmCon_MotCanc;

implementation

Uses Dm, Biblio, clsMotCancPedido;

{$R *.DFM}

var MotCancPedido : TMotCancPedido;
    tds           : Tdatasource;
    tq            : Tquery;

procedure TFrmCon_MotCanc.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Canp_codigo:=tq.fieldbyname('Canp_codigo').asstring;
  tds.free;
  tq.free;
end;

procedure TFrmCon_MotCanc.EdtDescricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=12 then begin
    FazConsulta;
    EdtDescricao.setfocus;
  end;
end;

procedure TFrmCon_MotCanc.FormActivate(Sender: TObject);
begin
  inherited;
  tds:=TDataSource.create(FrmCon_MotCanc);
  tq:=Tquery.create(FrmCon_MotCanc);
  tq.databasename:=dmint.db.databasename;
  tq.active:=False;
  tds.DataSet:=tq;
  fazconsulta;
  EdtDescricao.setfocus;
end;

procedure TFrmCon_MotCanc.FazConsulta;
begin
  if EdtDescricao.text='' then
    EdtDescricao.text := ' ';
  MotCancPedido:=TMotCancPedido.Create;
  MotCancPedido.Consultar(tq,EdtDescricao.text);
  tq.open;
  MotCancPedido.free;
  dbgMotCanc.DataSource := tds;
  dbgMotCanc.Refresh;
end;

end.
